package utils;

import java.io.File;

import javax.swing.JOptionPane;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;


public class Xsl {
	
     public static void transform(String xmlPath, String xsltPath,String destPath) 
	{
    	//Set saxon as transformer.
 		System.setProperty("javax.xml.transform.TransformerFactory",
 		"net.sf.saxon.TransformerFactoryImpl");
 		
		TransformerFactory tFactory = TransformerFactory.newInstance();

		try 
		{
			Transformer transformer = tFactory.newTransformer(new StreamSource(new File(xsltPath)));
			
			transformer.setOutputProperty(OutputKeys.INDENT, "yes");
			transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
			
			transformer.transform(new StreamSource(new File(xmlPath)),new StreamResult(new File(destPath)));
		} 
		catch (Exception e) 
		{
			 JOptionPane.showMessageDialog(null,e.getMessage());
		}
	}
}
